//
//  JwHttpConfig.h
//  JwPack
//
//  Created by 陈警卫 on 2024-08-29.
//

#import <Foundation/Foundation.h>

#import "JwMacro.h"
#import "JwCore.h"
#import "JwCate.h"
#import "JwSingle.h"
#import "JwExten.h"
#import "JwFrame.h"

NS_ASSUME_NONNULL_BEGIN

typedef NSString * kJwHttpHandelKey;

/// 打印台是否输出日志(默认1输出)
extern kJwHttpHandelKey const kJwHttpOwnerDebugLogKey;
/// 界面弹出提示(默认1提示)
extern kJwHttpHandelKey const kJwHttpOwnerErrorHudKey;

/// 调用requestHandel和requestLock时 不加锁(设置1不加锁)
extern kJwHttpHandelKey const kJwHttpOwnerNoLockKey;

/// 调用requestHandel和requestLock时 刷新(设置1刷新)
extern kJwHttpHandelKey const kJwHttpOwnerRefreshHeadersKey;
extern kJwHttpHandelKey const kJwHttpOwnerRefreshParamsKey;

typedef NSString kJwHttpMethod;

extern kJwHttpMethod *kJwHttpMethodDELETE;
extern kJwHttpMethod *kJwHttpMethodGET;
extern kJwHttpMethod *kJwHttpMethodHEAD;
extern kJwHttpMethod *kJwHttpMethodPATCH;
extern kJwHttpMethod *kJwHttpMethodPOST;
extern kJwHttpMethod *kJwHttpMethodPUT;
extern kJwHttpMethod *kJwHttpMethodQUERY;

extern kJwHttpMethod *kJwHttpMethodUPLOAD;
extern kJwHttpMethod *kJwHttpMethodDOWNLOAD;

typedef NS_ENUM(NSUInteger, JwHttpState) {
    JwHttpStateDefault,
    JwHttpStateStart,
    JwHttpStateRequest,
    JwHttpStateProgress, // 接口进度
    JwHttpStateResponse, // 接口成功
    JwHttpStateFinish, // 逻辑成功
    JwHttpStateError,
};

typedef NS_ENUM(NSUInteger, JwHttpDownPolicy) {
    JwHttpDownPolicyDefault,
    JwHttpDownPolicyCaches,
    JwHttpDownPolicyReload,
};

@interface JwHttpConfig : NSObject

/// 方式
@property (nonatomic, assign) kJwHttpMethod *method;
/// 地址
@property (nonatomic, strong) NSString *url;
/// 参数
@property (nonatomic, strong) NSMutableDictionary *params;
/// 头参数
@property (nonatomic, strong) NSMutableDictionary *headers;
/// 框架私有参数
@property (nonatomic, strong) NSMutableDictionary<kJwHttpHandelKey, id> *owners;

// MARK: - Request & Response

@property (nonatomic, assign) JwHttpState state;
@property (nonatomic, strong) NSURLSessionDataTask *task;
@property (nonatomic, strong) NSURLSessionDownloadTask *downloadTask;

@property (nonatomic, strong) id response; // 返回数据
@property (nonatomic, strong) NSError *error; // 返回错误

// MARK: - block
@property (nonatomic, copy) void(^comple)(JwHttpConfig *config);
@property (nonatomic, copy) void(^success)(NSURLSessionDataTask *task, id responseObject);
@property (nonatomic, copy) void(^failure)(NSURLSessionDataTask *task, NSError *error);

// MARK: - decode & model

// 解析模型路径 多级用"." ex( data.info )
@property (nonatomic, strong) NSString *decodePath;
@property (nonatomic, strong) NSString *decodeModelName; // 解析模型名称 className
@property (nonatomic, strong) id decode; // 解析数据(会根据decodePath自动推断解析为模型数组或模型)

// MARK: - down/upload

@property (nonatomic, strong) NSProgress *progress;
/// 下载策略(默认JwHttpDownPolicyCaches使用缓存)
@property (nonatomic, assign) JwHttpDownPolicy downPolicy;
@property (nonatomic, strong) NSURL *filePathURL;

/// 上传文件数据 key: 参数名称(String) value: 数据(Image/Url)
@property (nonatomic, strong) NSMutableDictionary *dataParams;

// MARK: - ui
@property (nonatomic, strong) UIView *loadView; // 加载框父视图
@property (nonatomic, strong) JwProgressHUD *hud; // 加载
@property (nonatomic, strong) UIScrollView *scrollView; // 滚动刷新视图



+ (JwHttpConfig *)configWithMethod:(kJwHttpMethod *)method
                             point:(nullable NSString *)point
                               url:(nullable NSString *)url
                            params:(nullable NSDictionary *)params
                           headers:(nullable NSDictionary *)headers
                            owners:(nullable NSDictionary *)owners;


@end

NS_ASSUME_NONNULL_END
